/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-08-31
 * Time: 10:13
 */

/*
 * 1.如和编写递归代码
 * 函数头  public ListNode reverseList(ListNode head)
 * 函数体
 * 将链表头放在反转后的末位
 * 然后再去反转前的链表
 * reverseList(head.next)
 * 2.递归函数出口
 * 链表头为空
 */
public class test_3 {

    public ListNode reverseList(ListNode head) {
        if (head == null) {
            return head;
        }
        if (head.next == null) {
            return head;
        }
        ListNode retnode = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return retnode;
    }

    public static void main(String[] args) {

    }
}